package com.summer.mall.controller;

import com.summer.mall.common.ResponseService;
import com.summer.mall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/detail")
    @ResponseBody
    public ResponseService getDetail(Integer productId){
        return productService.productDetail(productId);
    }

    @RequestMapping("/test")
    @ResponseBody
    public ResponseService getProduct(Integer productId){
        return productService.testFindProduct(productId);
    }

    @RequestMapping("/list")
    @ResponseBody
    public ResponseService getProductListByCategoryIdAndKeyword(@RequestParam(value="categoryId",required = false) Integer categoryId,
                                                                @RequestParam(value="keyword",required = false) String keyword,
                                                                @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                                                @RequestParam(value="pageSize",defaultValue = "10") Integer pageSize,
                                                                @RequestParam(value="orderBy",defaultValue = "") String orderBy){
        return productService.getProductByKeywordCategoryId(categoryId,keyword,pageNum,pageSize,orderBy);
    }
}
